let itemsApp=new Vue({
    el:"#itemsApp",
    data:{
        items:{}
    },
    methods:{
        loadItems:function () {
            let itemId=location.search;
            if (!itemId){
                alert("商品id不能为空");
                return;
            }
            itemId=itemId.substring(1)
            axios({
                url:"/items/"+itemId,
                method:"get"
            }).then(function (response) {
                itemsApp.items=response.data;
            })
        },

        addCart:function (itemsId) {
            //获得商品数量
            let quantity=$(".input-text").val();
            axios({
                url:"carts/add/"+itemsId+"/"+quantity,
                method:"get"
            }).then(function (response) {
                if (response.data == "ok"){
                    location.href="/cart.html"
                }else {
                    alert(response.data)
                    location.href="/cart.html"
                }
            })
        }
    },
    created:function () {
        this.loadItems();
    }

})